import axios from "axios";
import { TIME_OUT, BASE_URL } from "./config";
class ComposeRequest {
  constructor(baseURL, timeout) {
    this.instance = axios.create({
      baseURL,
      timeout,
    });
    this.instance.interceptors.response.use(
      (data) => {
        return data.data;
      },
      (err) => err
    );
  }

  request(config) {
    return this.instance.request(config);
  }

  get(config) {
    return this.request({ ...config, method: "get" });
  }

  post(config) {
    return this.request({ ...config, method: "post" });
  }
}
const requestInstance = new ComposeRequest(BASE_URL, TIME_OUT);

export default requestInstance;
